package info.wangyuan.agent.service.curd.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import info.wangyuan.agent.entity.po.AgentConfig;
import info.wangyuan.agent.entity.po.SystemPrompts;
import info.wangyuan.agent.exception.BusinessException;
import info.wangyuan.agent.mapper.AgentConfigMapper;
import info.wangyuan.agent.mapper.PromptMapper;
import info.wangyuan.agent.service.curd.PromptService;
import org.springframework.stereotype.Service;

/**
 * 提示词服务实现类
 *
 * @author Albert
 * @since 2025-07-15 00:46:55
 */
@Service
public class PromptServiceImpl extends ServiceImpl<PromptMapper, SystemPrompts> implements PromptService {

    private final AgentConfigMapper agentConfigMapper;

    public PromptServiceImpl(AgentConfigMapper agentConfigMapper) {
        this.agentConfigMapper = agentConfigMapper;
    }

    /**
     * 检查提示词模版是否被使用
     */
    @Override
    public void canDelete(Integer id) {
        AgentConfig agentConfig = agentConfigMapper.selectOne(Wrappers.lambdaQuery(AgentConfig.class).eq(AgentConfig::getId, id));
        if (agentConfig != null) {
            throw new BusinessException("该提示词模版已被智能体配置，无法删除");
        }
        removeById(id);
    }
}
